//
//  ZWDrawViewController.m
//  MyTest
//
//  Created by rayootech on 15/9/26.
//  Copyright (c) 2015年 rayootech. All rights reserved.
//

#import "ZWDrawViewController.h"
#define KrowH 40
@interface ZWDrawViewController ()

@end

@implementation ZWDrawViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
     self.title=@"画Cell";
    
    [self drawCell];
}

-(void)drawCell{
   
    UIView *newView=[[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height)];
    [self.view addSubview:newView];
    /**
     *  思路:先画一个0,0,320,30 的矩形，在矩形的底部加入一根线 然后将矩形平铺到控件中
     *
     *
     */
    //1、创建一行背景图片
    CGFloat rowW=self.view.frame.size.width;
    CGFloat rowH=KrowH;
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(rowW, rowH), NO, 0.0);
    
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    //画矩形框
    [[UIColor redColor]set];
    CGContextAddRect(ctx, CGRectMake(0, 0, rowW, rowH));
    CGContextFillPath(ctx);
    
    // 画线
    [[UIColor greenColor]set];
    CGFloat lineW=2;
    CGContextSetLineWidth(ctx, lineW);
    CGFloat dividerX=0;
    //距离底部2个像素的距离
    CGFloat dividerY=rowH-lineW;
    CGContextMoveToPoint(ctx, dividerX, dividerY);
    CGContextAddLineToPoint(ctx, rowW-dividerX, dividerY);
    CGContextStrokePath(ctx);
    
    //3、取图
    UIImage *newImg=UIGraphicsGetImageFromCurrentImageContext();
    
    //4、结束上下文
    UIGraphicsEndImageContext();
    
    //5、设置为背景pattern表示样板平铺
    newView.backgroundColor=[UIColor colorWithPatternImage:newImg];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
